##########################################################################################
#
#   Functions




#	dir_file
#		prints only last directory+file
#
#		$(call dir_file,FILE_NAME)

dir_file=$(notdir $(patsubst %/,%,$(dir $(1))))/$(notdir $(1))









#	create_unless_exists
#
#		create file unless already exists
#
#		$(call create_unless_exists,FILE_NAME)

create_unless_exists= if [[ ! -f $(1) ]]; then \
echo "	$(call dir_file,$(1)) is not present. Create empty placeholder"; touch $(1); fi


#
#	log_message
#		$(1) = module_name (e.g. make align)
#		$(2) = message
#		$(3) = file
#


log_message = \
        printf "%s %s %-40s %s\n" `date "+%d/%m/%G (%T)"` $(1) $(2) >> $(3); \
        echo "	"$(2)   $(NOECHO1)

log_message2 = \
        printf "%s %s %-40s %s\n" `date "+%d/%m/%G (%T)"` $(1) $(2) >> $(3); \
        echo "	"$(2)   $(NOECHO2)





#
#	consolidate_non_empty_files
#
#		merges non empty files into single file. Deletes empty files
#
#		$(call consolidate_non_empty_files,DIR,WILDCARD,RESULT_FILE)


consolidate_non_empty_files= \
        @echo "	Consolidate to $(3)"   $(NOECHO1); \
	rm -f $(3); \
        find $(1) -name "$(2)" -empty -print0 \
	| xargs -0 -i rm {} ; \
        find $(1) -name "$(2)"  -print0 \
        | xargs -0 -i bash -c "echo '{}' >> $(3); cat '{}' >> $(3); echo >> $(3)"; \
        find $(1) -name "$(2)"  -print0 | xargs -0 -i rm {}
#
#
#
#
##########################################################################################




